﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Google.GData.Calendar;
using Google.GData.Extensions;
using Google.GData.Client;

namespace GJReminder.ViewModel.Command
{
    class CreateEventCommand : ICommand
    {
        private ViewModel.ConsoleViewModel m_consoleViewModel;

        public CreateEventCommand(ViewModel.ConsoleViewModel consoleViewModel)
        {
            m_consoleViewModel = consoleViewModel;
        }

        #region ICommand Members

        bool ICommand.CanExecute(object parameter)
        {
            throw new NotImplementedException();
        }

        event EventHandler ICommand.CanExecuteChanged
        {
            add { throw new NotImplementedException(); }
            remove { throw new NotImplementedException(); }
        }

        void ICommand.Execute(object parameter)
        {
            EventEntry entry = new EventEntry();

            // Set the title and content of the entry.
            entry.Title.Text = m_consoleViewModel.CreateEventModel.Title;
            entry.Content.Content = m_consoleViewModel.CreateEventModel.Description;

            // Set a location for the event.
            Where eventLocation = new Where();
            eventLocation.ValueString = m_consoleViewModel.CreateEventModel.Location;
            entry.Locations.Add(eventLocation);

            When eventTime = new When(m_consoleViewModel.CreateEventModel.StartTime, m_consoleViewModel.CreateEventModel.EndTime);
            entry.Times.Add(eventTime);

            //Uri postUri = new Uri(App.SecurityContext.AlterUrl);
                //"http://www.google.com/calendar/feeds/ti07tqgpe5rsr2c7lqrc4hmp34%40group.calendar.google.com/private/full");

            // Send the request and receive the response:
            AtomEntry insertedEntry = App.SecurityContext.Service.Insert(entry);
        }

        #endregion
    }
}
